//
//  ForgetViewController.m
//  SuperMedical
//
//  Created by 赵隆杰 on 2018/7/28.
//  Copyright © 2018年 赵隆杰. All rights reserved.
//

#import "ForgetViewController.h"
#import "UserEditApi.h"

@interface ForgetViewController ()
@property (weak, nonatomic) IBOutlet UIView *inputView;
@property (weak, nonatomic) IBOutlet UIImageView *moblieImage;
@property (weak, nonatomic) IBOutlet UITextField *moblieField;
@property (weak, nonatomic) IBOutlet UIImageView *passwordImage;
@property (weak, nonatomic) IBOutlet UITextField *passwordField;
@property (weak, nonatomic) IBOutlet UIView *forgetView;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
@property (weak, nonatomic) IBOutlet UITextField *confirmField;

@end

@implementation ForgetViewController

//- (void)viewWillAppear:(BOOL)animated {
//    [super viewWillAppear:animated];
//    [self.navigationController setNavigationBarHidden:YES animated:NO];
//}
//
//- (void)viewWillDisappear:(BOOL)animated {
//    [super viewWillDisappear:animated];
//    [self.navigationController setNavigationBarHidden:NO animated:NO];
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self configView];
}

- (void)configView
{
    self.loginBtn.layer.cornerRadius = self.loginBtn.height/2;
    self.loginBtn.layer.masksToBounds = YES;
}

- (IBAction)loginClick:(id)sender {
    NSLog(@"修改密码");
    
    [self.view endEditing:YES];
    if ([self.moblieField.text isEqualToString:@""]) {
        [self.view makeToast:@"请输入手机号" duration:2.0 position:CSToastPositionCenter];
        return;
    }
    if (![self.passwordField.text isEqualToString:self.confirmField.text]) {
        [self.view makeToast:@"两次密码不一致" duration:2.0 position:CSToastPositionCenter];
        return;
    }
    //登录接口不传token和uid
    UserEditApi *api = [[UserEditApi alloc] initWithFeedback:@"" username:self.moblieField.text nickname:@"" password:self.passwordField.text userpic:@""];
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        if (api.success) {
            VHWeakSelf
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"修改成功，请返回重新登录" preferredStyle:UIAlertControllerStyleAlert];
            [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                VHStrongSelf
                [self.navigationController popViewControllerAnimated:YES];
            }]];
            [[UIWindow currentViewController] presentViewController:alertController animated:YES completion:nil];
        }
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
    }];
    
}

- (IBAction)hasAccountClick:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
